<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>loginLog管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">


</head>
<body class="hold-transition">
<div id="app">
    <table width="400px" align="center" >
        <tr>
            <td>
                <el-form label-width="80px">
                    <el-form-item label="用户名" >
                        <el-input v-model="searchMap.username"></el-input>
                    </el-form-item>
                    <el-form-item label="原密码">
                        <el-input v-model="searchMap.oldPassword"  type="password"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" >
                        <el-input v-model="searchMap.newPassword"   type="password" ></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码" >
                        <el-input v-model="searchMap.checkPassword"  type="password"  ></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="check()">提交</el-button>
                    </el-form-item>
                </el-form>
            </td>
        </tr>
    </table>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data(){
            return {
                searchMap:{},
            }
        },
        created(){
            axios.get(`/main/findUsername.do`).then(response=>{
                this.searchMap.username=response.data;
            })
        },
        methods:{
            check(){
                if(this.searchMap.newPassword==this.searchMap.checkPassword){
                    //发送ajax请求
                    axios.post(`/main/editPassword.do`,this.searchMap).then(response=>{
                        if(response.data.code==1){
                            this.$alert(response.data.message);
                        }else{
                            //修改成功，跳转到首页
                            location.href="/main.html";
                        }
                    })
                }else{
                    //修改后的密码两次不相同
                    this.$alert("请输入相同的密码");
                }
            }
        }

    })
</script>
</html>
